<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/view/common/includes.jsp" %>
<%@ include file="/WEB-INF/view/inc.jsp" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<style>
    .panel-body {
        border-bottom-width: 0px;
        border-left-width: 0px;
    }

    .layout-expand .panel-header {
        border-width: 0px;
    }

</style>
<body class="easyui-layout" data-options="fit:true,border:false">
<!-- 搜索框 -->
<div data-options="region:'north',title:'查询条件',border:false" style="height:80px; overflow: hidden;border: 0px;">
    <form id="searchForm">
        <div class="fitem fl">
            <label>订单号:</label>
            <input name="id" class="easyui-textbox">
        </div>
        <div class="dialog_item">
            <label>订单状态:</label>
            <input id="orderStatus_change" style="width: 100px;" name="orderStatus" editable="false" value="${order.orderStatus}"
                   class="easyui-combobox" data-options="valueField : 'code',
	    						textField : 'name', url:'<%=contextPath%>/sys/codeItems/byCategoryCode?categoryCode=orderStatus',
								panelHeight:'auto'
							"/>
        </div>
        <div class="fitem searchItem fr">
            <a class="easyui-linkbutton" iconCls="icon-search" onclick="sy_searchFun()">搜索</a>
            <a class="easyui-linkbutton" iconCls="icon-reload" onclick="sy_resetFun()">重置</a>
        </div>
    </form>
</div>
<div data-options="region:'center',border:false">
    <table id="grid" class="easyui-datagrid" fit="true"
           data-options="url: '<%=contextPath%>/order/list',method: 'post',pagination: true,rownumbers:true,idField: 'id',
           fitColumns:true,singleSelect:true,queryParams: {	orderStatus: 1},striped:true,sortName:'createTime',sortOrder:'desc',toolbar: '#toolbar'">
        <thead>
        <tr>
            <th data-options="field:'id'" width="100" sortable="true">订单号</th>
            <th data-options="field:'createTime'" width="100" sortable="true">订单日期</th>
            <th data-options="field:'totalAmount'" width="100" sortable="true">总金额</th>
            <th data-options="field:'cashPayment'" width="100" sortable="true">现金支付金额</th>
            <th data-options="field:'couponPayment'" width="100" sortable="true">优惠券抵用</th>
            <th data-options="field:'shippingAddress'" width="100" sortable="true">地址</th>
            <th data-options="field:'shippingName'" width="100" sortable="true">收货人</th>
            <th data-options="field:'shippingTel'" width="100" sortable="true">收货人电话号码</th>
            <th data-options="field:'orderStatus',dictionary:'orderStatus',formatter:sy_dict" width="100" sortable="true">订单状态</th>
        </tr>
        </thead>
    </table>
</div>
<!-- 按钮-->
<div id="toolbar" style="display: none;">
    <t:button action="order_details" iconCls="icon-add" buttonName="详情" onclick="order_details('/order/details/','order详细信息',600,850)"/>
    <t:button action="order_print" iconCls="icon-add" buttonName="批量打印" onclick="sy_print('/order/toSaveAndUpdate/','order信息')"/>
    <t:button action="order_print" iconCls="icon-add" buttonName="发货" onclick=" shipments('/order/toShipments','','发货')"/>
    <t:button action="order_print" iconCls="icon-add" buttonName="取消" onclick="cancel('/order/cancel','','确定取消')"/>
    <%--<t:button action="order_add" iconCls="icon-add" buttonName="新增" onclick="sy_addFun('/order/toSaveAndUpdate/','添加order信息')"/>
    <t:button action="order_edit" iconCls="icon-edit" buttonName="编辑" onclick="sy_editFun('/order/toSaveAndUpdate/','修改order信息')"/>
    <t:button action="order_remove" iconCls="icon-remove" buttonName="删除" onclick="sy_removeGridFun_tip('/order/delete')"/>--%>
</div>
<script>
    var $grid;
    $(function(){
        $(document).ready(function () {
            $("#orderStatus_change").combobox({
                onChange: function (n,o) {
                    $("#grid").datagrid({
                        queryParams: {
                            orderStatus: n
                        }
                    })

                }

            });

        });
    })

    var order_details  = function(url, title, height, width){
        debugger;
        sy_showFun(url, title, height, width);

    }

/**
 * 查看订单详情操作
 * @param url 请求路径
 * @param title 标题
 * @param grid 列表
 * @param width 长度
 * @param height 高度
 * @param $menuTree 菜单列表
 */
    var sy_showFun = function (url, title, height, width, $grid, $menuTree) {
        if (!$grid) {
            $grid = $("#grid");
        }
        var rows = $grid.datagrid('getSelections');
        if (rows.length == 0) {
            parent.$.messager.alert('提示', "请选择一条数据", 'error');
        } else if (rows.length > 1) {
            parent.$.messager.alert('提示', "只能选择一条数据", 'error');
        } else {
            url = url + "/" + rows[0].id;
            var dialog = parent.sy.modalDialog({
                title: title,
                width: width,
                height: height,
                url: url,
                buttons: [{
                    text: '取消',
                    iconCls: "icon-cancel",
                    handler: function () {
                        dialog.dialog('destroy');
                    }
                },{
                    text: '打印',
                    iconCls: "icon-edit",
                    handler: function () {
                        dialog.find('iframe').get(0).contentWindow. window.print();
                    }
                }]
            });

        }
    }

/**
* 取消
*
 */
var cancel = function(url, $grid, tip){
    var rows = $("#grid").datagrid('getSelections');
        if(rows.length>0){
            var falg = true;
            $.each(rows,function(i,item){
                if(item.orderStatus!=0){
                    falg = false;
                    parent.$.messager.alert('提示', "请选择未付款的商品", 'error');
                    return false;
                }
            })
            if(falg){
                sy_removeGridFun_tip(url, $grid, tip);
            }
        }else{
            parent.$.messager.alert('提示', "请选择商品", 'error');
        }
}

    var shipments = function(url){
        sy_editFun(url);
    }

</script>

</body>
</html>



